package cn.regexp.web.controller;

import cn.hutool.core.date.DateUtil;
import cn.regexp.domain.ShopIngredientBook;
import cn.regexp.domain.ShopUser;
import cn.regexp.redis.service.IShopUserRedisService;
import cn.regexp.service.IIngredientBookService;
import cn.regexp.utils.JsonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("ingredientBook")
public class IngredientBookController {
    @Autowired
    private IIngredientBookService ingredientBookService;
    @Autowired
    private IShopUserRedisService userRedisService;

    @ApiOperation(value = "选定食材订餐", notes = "选定食材订餐")
    @PostMapping("/submitIngredientBook")
    public JsonResult<String> submitIngredientBook(@RequestBody ShopIngredientBook ingredientBook,
                                                   HttpServletRequest request) {
        String token = request.getHeader("token");
        ShopUser shopUser = userRedisService.getUserByToken(token);
        ingredientBook.setBookUserId(shopUser.getId());
        ingredientBook.setInsertTime(DateUtil.date());
        ingredientBook.setIsDel(ShopIngredientBook.NO);
        ingredientBookService.save(ingredientBook);
        return JsonResult.success();
    }

}
